import {createRouter, createWebHashHistory} from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: "/",
        name: "Home",
        component: Home,
        children:
        [
            {
                path: "/fileList",
                name: "fileList",
                meta: {
                    title: '我的文件'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/file/FileList.vue")
            },
            {
                path: "/modelList",
                name: "modelList",
                meta: {
                    title: '机器学习模型'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/ml/ModelList.vue")
            },
            {
                path: "/fileDetail",
                name: "fileDetail",
                meta: {
                    title: '文件详情'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/file/FileDetail.vue")
            },
            {
                path: "/config",
                name: "config",
                meta: {
                    title: '模型配置'
                },
                component: () => import ( /* webpackChunkName: "table" */ "../views/ml/ConfigList.vue")
            },
            {
                path: "/predictionList",
                name: "predictionList",
                meta: {
                    title: '预测结果列表'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/ml/PredictionList.vue")
            },
            {
                path: "/predictionDetail",
                name: "predictionDetail",
                meta: {
                    title: '预测结果详情'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/ml/PredictionDetail.vue")
            },
            {
                path: "/analysisConfig",
                name: "analysisConfig",
                meta: {
                    title: '数据统计配置'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/analysis/AnalysisConfig.vue")
            },
            {
                path: "/analysisConfigDetail",
                name: "analysisConfigDetail",
                meta: {
                    title: '数据统计配置详情'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/analysis/AnalysisConfigDetail.vue")
            },
            {
                path: "/analysis",
                name: "analysis",
                meta: {
                    title: '数据分析'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/analysis/Analysis.vue")
            },
            {
                path: "/analysisHistory",
                name: "analysisHistory",
                meta: {
                    title: '数据分析结果'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/analysis/AnalysisHistory.vue")
            },
            {
                path: "/analysisPipeline",
                name: "analysisPipeline",
                meta: {
                    title: '数据分析流水线'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/analysis/AnalysisPipeline.vue")
            },
            {
                path: "/mlPipeline",
                name: "mlPipeline",
                meta: {
                    title: '机器学习流水线'
                },
                component: () => import ( /* webpackChunkName: "charts" */ "../views/ml/MLPipeline.vue")
            },
            {
                path: "/upload",
                name: "upload",
                meta: {
                    title: '文件上传'
                },
                component: () => import ( /* webpackChunkName: "upload" */ "../views/file/Upload.vue")
            },
            {
                path: "/square",
                name: "square",
                meta: {
                    title: '数据广场'
                },
                component: () => import ( /* webpackChunkName: "upload" */ "../views/square/Square.vue")
            },
            {
                path: "/shareFileDetail",
                name: "shareFileDetail",
                meta: {
                    title: '共享文件详情'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/square/ShareFileDetail.vue")
            },
            {
                path: "/collectFileDetail",
                name: "collectFileDetail",
                meta: {
                    title: '收藏文件详情'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/square/CollectFileDetail.vue")
            },
            {
                path:'/ConfigDetail',
                name:'configdetail',
                meta:{
                    title:'配置详情'
                },
                component:()=>import(/*webpackChunkName:"configform" */ '../views/ml/ConfigDetail.vue')
            },
            {
                path:'/Deployment',
                name:'Deployment',
                meta:{
                    title:'模型部署'
                },
                component:()=>import(/*webpackChunkName:"configform" */ '../views/ml/Deployment.vue')
            },
            {
                path:'/predictionAll',
                name:'predictionAll',
                meta:{
                    title:'预测结果'
                },
                component:()=>import(/*webpackChunkName:"configform" */ '../views/ml/PredictionAll.vue')
            },
        ]
    },
    {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import ("../views/user/Login.vue")
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | vue-manage-system`;
    const role = localStorage.getItem('ms_username');

    if (!role && to.path !== '/login') {
        next('/login');
    } else if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        role === 'admin'
            ? next()
            : next('/403');
    } else {
        next();
    }
    next();
});

export default router;
